package cn.com.pc.content.domain.metadata;

import cn.com.pc.content.domain.Biz;
import cn.com.pc.content.domain.content.ContentType;
import cn.com.pc.content.domain.Site;
import cn.com.pc.content.jpa.BizConverter;
import cn.com.pc.content.jpa.ContentDataTypeConverter;
import cn.com.pc.content.jpa.ContentTypeConverter;
import cn.com.pc.content.jpa.SiteConverter;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import lombok.ToString;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * 物料元数据属性映射表
 */
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "content_property")
@Data
@ToString
public class ContentProperty {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "name")
    private String name;

    @Column(name = "site")
    @Convert(converter = SiteConverter.class)
    private Site site;

    @Column(name = "biz")
    @Convert(converter = BizConverter.class)
    private Biz biz;

    @Column(name = "content_type")
    @Convert(converter = ContentTypeConverter.class)
    private ContentType contentType;

    @Column(name = "data_type")
    @Convert(converter = ContentDataTypeConverter.class)
    private ContentDataType dataType;

    @Column(name = "has_index")
    private Boolean hasIndex;

    @Column(name = "need_audit")
    private Boolean needAudit;

    @JsonIgnore
    @Column(name = "deleted")
    private boolean deleted;

    @JsonFormat(timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @Column(name = "created_at")
    private LocalDateTime createdAt;

    @Column(name = "created_by")
    private String createdBy;

}
